import cv2
import matplotlib.pyplot as plt

img1 = cv2.imread('flower.jpeg')
img2 = img1.copy()

# x方向向右平移100
for j in range(521):
    for i in range(520,-1,-1):
        if i<100:
            img2[j, i] = 0
        else:
            img2[j, i] = img2[j, i-100]

# y方向向下平移50
for u in range(521):
    for v in range(520,-1,-1):
        if v<50:
            img2[v, u] = 0
        else:
            img2[v, u] = img2[v-50, u]

# 图像显示
fig, axes = plt.subplots(1, 2, figsize=(10, 8), dpi=100)
axes[0].imshow(img1[:, :, ::-1])
axes[0].set_title("original")
axes[1].imshow(img2[:, :, ::-1])
axes[1].set_title("after translation")

plt.show()